#include "btform.h"
#include "ui_btform.h"

btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);
    ui->lineBox->hide();//先隐藏
    //定义动画对象
    animationLine1 = new QPropertyAnimation(ui->line1,"geometry",this);
    animationLine2 = new QPropertyAnimation(ui->line2,"geometry",this);
    animationLine3 = new QPropertyAnimation(ui->line3,"geometry",this);
    animationLine4 = new QPropertyAnimation(ui->line4,"geometry",this);
    //设置动画的持续时间
    animationLine1->setDuration(1500);//设置动画执行完的时间
    //设置动画的关键字,分为3步，起始0 中间态最高 终止态0
    animationLine1->setKeyValueAt(0,QRect(0,22,2,0));
    animationLine1->setKeyValueAt(0.5,QRect(0,7,2,15));
    animationLine1->setKeyValueAt(1,QRect(0,22,2,0));
    animationLine1->setLoopCount(-1);//无限循环
    animationLine1->start();//启动动画

    //设置动画的持续时间
    animationLine2->setDuration(1600);//设置动画执行完的时间
    //设置动画的关键字,分为3步，起始0 中间态最高 终止态0
    animationLine2->setKeyValueAt(0,QRect(5,22,2,0));
    animationLine2->setKeyValueAt(0.5,QRect(5,7,2,15));
    animationLine2->setKeyValueAt(1,QRect(5,22,2,0));
    animationLine2->setLoopCount(-1);//无限循环
    animationLine2->start();//启动动画

    //设置动画的持续时间
    animationLine3->setDuration(1700);//设置动画执行完的时间
    //设置动画的关键字,分为3步，起始0 中间态最高 终止态0
    animationLine3->setKeyValueAt(0,QRect(10,22,2,0));
    animationLine3->setKeyValueAt(0.5,QRect(10,7,2,15));
    animationLine3->setKeyValueAt(1,QRect(10,22,2,0));
    animationLine3->setLoopCount(-1);//无限循环
    animationLine3->start();//启动动画


    //设置动画的持续时间
    animationLine4->setDuration(1800);//设置动画执行完的时间
    //设置动画的关键字,分为3步，起始0 中间态最高 终止态0
    animationLine4->setKeyValueAt(0,QRect(15,22,2,0));
    animationLine4->setKeyValueAt(0.5,QRect(15,7,2,15));
    animationLine4->setKeyValueAt(1,QRect(15,22,2,0));
    animationLine4->setLoopCount(-1);//无限循环
    animationLine4->start();//启动动画
}

btForm::~btForm()
{
    delete ui;
}

void btForm::setIcon(const QString btIcon, const QString content, int pageId)
{
    ui->btIcon->setPixmap(btIcon);
    ui->btText->setText(content);
    this->pageId = pageId;
}

void btForm::mousePressEvent(QMouseEvent *event)
{
    //鼠标点击事件
    if(event->button() == Qt::LeftButton)
    {
        //开始改变样式
        ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}*{color:#f6f6f6;}");

        //发射emit
        emit clicked(this->pageId);//为了后面改变页面
        return;
    }
    QWidget::mouseMoveEvent(event);//其他交给QWidget处理
}

void btForm::clearBg()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#d8d8d8;}");
}

void btForm::showAnimation(bool isShow)
{
    if(isShow)
        ui->lineBox->show();
    else
        ui->lineBox->hide();
}

void btForm::changeColor()
{
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}*{color:#f6f6f6;}");
}
